Engine.Camera = function(position, lookat, worldup, FOV){
    this.position = position || new Engine.Vector3(0,0,-10);
    this.lookat = lookat || new Engine.Vector3(0,0,0);
    this.worldup = worldup || new Engine.Vector3(0,1,0);
    this.FOV = FOV || 60;
    this.worldup = this.worldup.normalize();
};

Engine.Camera.prototype = (function(){

    return {
        d: function(){
            return 1 / (Math.tan(this.FOV * Math.PI / 360));
        },
        w2c: function(){
            var Z = this.lookat.minus(this.position).normalize();
            var X = this.worldup.cross(Z).normalize();
            var Y = Z.cross(X).normalize();

            var m = new Engine.Matrix4x4();
            m.m00 = X.x;
            m.m01 = X.y;
            m.m02 = X.z;
            m.m03 = -X.dot(this.position);
            m.m10 = Y.x;
            m.m11 = Y.y;
            m.m12 = Y.z;
            m.m13 = -Y.dot(this.position);
            m.m20 = Z.x;
            m.m21 = Z.y;
            m.m22 = Z.z;
            m.m23 = -Z.dot(this.position);
            m.m33 = 1;
            return m;
        },
        c2p : function(){
            var m = new Engine.Matrix4x4();
            m.m00 = 1;
        	m.m11 = 1;
        	m.m22 = 1;
        	m.m33 = 1;
        	m.m32 = 1/this.d();
        	return m;
        }
    };
})();